<?php

namespace app\admin\service;

use app\admin\dao\TradeDao;
use app\admin\model\UM as UM;
use app\common\model\Trade;
use ShidianUtil\Utils\TimeUtil;

/**
 * Class TradeService
 * @package app\admin\service
 */
class TradeService
{
    // dao
    private TradeDao $tradeDao;

    public function __construct(TradeDao $tradeDao)
    {
        $this->tradeDao = $tradeDao;
    }

    public function index(?UM $user, $memberId, $provinceId, $cityId, $payMethod, $categoryId, $serverId, $status, $startTime, $endTime, $kw, ?int $page = null, ?int $page_size = null): array
    {
        if(is_numeric($endTime)){
            $endTime = TimeUtil::stamp(TimeUtil::DAY, $endTime, false);
        }
        return $this->tradeDao->listTrades($memberId, $provinceId, $cityId, $payMethod, $categoryId, $serverId, $status, $startTime, $endTime, $kw, $page, $page_size);
    }

    /**
     * 已售案源-列表
     * @param UM|null $user
     * @param $categoryId
     * @param $provinceId
     * @param $cityId
     * @param $startTime
     * @param $endTime
     * @param $kw
     * @param int|null $page
     * @param int|null $page_size
     * @return array
     */
    public function indexLawCases(?UM $user, $categoryId, $provinceId, $cityId, $status, $startTime, $endTime, $kw, ?int $page = null, ?int $page_size = null): array
    {
        if(is_numeric($endTime)){
            $endTime = TimeUtil::stamp(TimeUtil::DAY, $endTime, false);
        }
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->tradeDao->listLawCases($categoryId, $provinceId, $cityId, $status, $startTime, $endTime, $kw, $page, $page_size);
    }

    /**
     * 查询
     * @param UM|null $user
     * @param int $id
     * @return Trade
     */
    public function read(?UM $user, int $id): ?Trade
    {
        //这里如果要修改查询，建议把查询放到dao层去
        return $this->tradeDao->findByPK($id, true);
    }

}
